<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>患者库</title>
  <script type="text/javascript" src="../js/jquerysession.js"></script>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

  <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

  <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js">
  </script>
</head>

<body>

<div class="container-fluid">
  <div class="row-fluid">
    <div class="col-md-12">
      <table class="table">
        <thead>
        <tr>
          <th>
            编号
          </th>
          <th>
            学生姓名
          </th>
          <th>
            诊断结果
          </th>

          <th>
            配药情况
          </th>

        </tr>
        </thead>
        <tbody id="patientTab">

        </tbody>
      </table>
    </div>
  </div>
</div>

</body>


<script>

  $(function () {
    $.ajax({
              url:"/diagnosis/findAll",
              type:"POST",
              data: null,
              // async: false,

              success: function(result){
                if (result.state == 200){
                  var dia = result.data;
                  $("#patientTab").html('');
                  $.each(dia,function (i) {
                    $tr = $("<tr/>");

                    $td1 = $("<td/>").text(dia[i].cr_ID);

                    var studentID;
                    var studentName;
                    $.ajax({
                      url:"/clinicReg/findById",
                      type:"POST",
                      async: false,
                      data: {
                        cr_ID:dia[i].cr_ID
                      },

                      success:function (rst) {
                        if(rst.state==200){
                          studentID = rst.data.st_ID;
                        }
                      }
                    });


                    $.ajax({
                      url:"/student/findByID",
                      type:"POST",
                      async: false,
                      data: {
                       st_ID:studentID,
                      },
                      success:function (rst) {
                        if(rst.state==200){
                          studentName = rst.data.realName;

                        }
                      }
                    });
                    $td2 = $("<td/>").text(studentName);
                    $td3 = $("<td/>").text(dia[i].dg_info);
                    var med_list;
                    $.ajax({
                      url:"/diagnosis/findByCr_Id",
                      type:"POST",
                      async: false,
                      data: {
                        cr_ID:dia[i].cr_ID,
                      },
                      success:function (rst) {
                        if(rst.state==200){
                          med_list = rst.data.med_ID_List;
                        }
                      }
                    });

                    var med_list_scr = [];
                    $.ajax({
                      url:"/medicine/findById_List",
                      type:"POST",
                      async: false,
                      data: {
                        id_list:med_list,
                      },
                      success:function (rst) {
                        if(rst.state==200){
                          for(var i =0;i<(med_list.length+1)/2;i++){
                            med_list_scr.push(rst.data[i].med_Name);


                          }
                        }
                      }
                    })

                    console.log(med_list_scr)
                    $td4 = $("<td/>").text(med_list_scr);


                    $tr.append($td1).append($td2).append($td3).append($td4);

                    $("#patientTab").append($tr);
                  });


                }


              }
            }
    );
  })

</script>
</html>